package com.lagou.edu.service.impl;

import com.lagou.edu.dao.IResumeDao;
import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.IResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Kirito
 * @description:
 * @date 2020/04/11
 */
@Service
public class ResumeServiceImpl implements IResumeService {

    @Autowired
    private IResumeDao resumeDao;

    @Override
    public List<Resume> findAll() {
        return resumeDao.findAll();
    }

    @Override
    public Resume findById(Long id) throws Exception {
        return resumeDao.findById(id).orElse(null);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean save(Resume resume) throws Exception {
        Resume dbResume = resumeDao.save(resume);
        return dbResume.getId() == 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean update(Resume resume) throws Exception {
        Resume dbResume = resumeDao.save(resume);
        return dbResume.getId() == 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(Long id) throws Exception {
        resumeDao.deleteById(id);
        return true;
    }
}
